$().ready(function() {
    $("#user_form").validate({
        errorElement: "em",
        errorContainer: $("#warning"),
        errorPlacement: function(error, element) {
            error.appendTo( element.next("span"));
        },
        success: function(label) {
            label.text("ok!").addClass("success");
        },
        rules: {
            "user[login]": {
                required: true,
                minlength: 3,
                maxlength: 20,
                remote: "/users/check_login"
            },
            "user[email]": {
                required: true,
                email: true,
                remote: "/users/check_email"
            },
            "user[password]": {
                required: true,
                minlength: 5,
                maxlength: 20
            },
            "user[password_confirmation]": {
                required: true,
                equalTo: "#user_password"
            }
        },
        messages: {
            "user[login]": {
                remote: "抱歉,用户名已存在.",
                required: "请输入用户名."
            },
            "user[email]": {
                required: "请输入邮箱",
                remote: "抱歉,邮箱已存在."
            },
            "user[password]": {
                required: "请输入密码.",
                minlength: "太短."
            },
            "user[password_confirmation]": {
                required: "请重复密码",
                equalTo: "两次密码不一致"
            }
        }

    });
});
